﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhittleList.Bll;
using System.Data.Linq;
using WhittleList.Tests.Helpers;

namespace WhittleList.Tests.Mocks
{
    public class FakeSection : Moq.Mock<Section>
    {
        public static List<FakeSection> GetList(int number)
        {
            return GetList(number, new Random());
        }

        public static List<FakeSection> GetList(int number, Random rnd)
        {
            var tmp = new List<FakeSection>();
            while (tmp.Count < number)
            {
                var i = tmp.Count + 1;
                tmp.Add(new FakeSection(i, string.Format("Section {0}", i), MockHelpers.CreateBinary(rnd)));
            }
            return tmp;
        }

        public FakeSection(int id, string name, System.Data.Linq.Binary cid)
        {
            this.Setup(x => x.Id).Returns(id);
            this.SetupProperty(x => x.Name, name);
            this.Setup(x => x.CID).Returns(cid);
        }


        internal void SetProject(FakeProject project)
        {
            this.Setup(x => x.Project).Returns(project.Object);
            this.Setup(x => x.ProjectId).Returns(project.Object.Id);
        }

        internal void SetItems(List<FakeItem> items)
        {
            var tmp = new EntitySet<Item>();
            tmp.Assign(items.Convert());
            this.Setup(x => x.Items).Returns(tmp);
            items.ForEach(x => x.SetSection(this));
        }

    }
}
